using LangChainServer.Models;
using LangChainServer.Services;
using Microsoft.AspNetCore.Mvc;

namespace LangChainServer.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class LangChainController : ControllerBase
    {
        private readonly ILangChainService _service;

        public LangChainController(ILangChainService service)
        {
            _service = service;
        }

        [HttpPost("chat-once")]
        /// <summary>
        /// 单轮对话：不保留上下文，直接返回模型回复。
        /// </summary>
        /// <param name="request">请求体，包含用户输入、可选模型与温度等参数。</param>
        /// <param name="ct">取消标记。</param>
        /// <returns>返回回复内容与使用的模型信息。</returns>
        public async Task<ActionResult<LangChainChatResponse>> ChatOnce([FromBody] LangChainChatRequest request, CancellationToken ct)
        {
            var res = await _service.ChatOnceAsync(request, ct);
            return Ok(res);
        }

        [HttpPost("chat-memory")]
        /// <summary>
        /// 多轮对话：基于 SessionId 维护简单的内存上下文。
        /// </summary>
        /// <param name="request">请求体，必须包含 SessionId 用于区分会话。</param>
        /// <param name="ct">取消标记。</param>
        /// <returns>返回回复内容与使用的模型信息。</returns>
        public async Task<ActionResult<LangChainChatResponse>> ChatWithMemory([FromBody] LangChainChatRequest request, CancellationToken ct)
        {
            var res = await _service.ChatWithMemoryAsync(request, ct);
            return Ok(res);
        }

        [HttpPost("structured")]
        /// <summary>
        /// 结构化回答：按固定结构输出“问题分类/回答内容/建议操作”。
        /// </summary>
        /// <param name="request">请求体，支持传入分类与问题内容。</param>
        /// <param name="ct">取消标记。</param>
        /// <returns>返回结构化的文本内容。</returns>
        public async Task<ActionResult<LangChainChatResponse>> Structured([FromBody] LangChainChatRequest request, CancellationToken ct)
        {
            var res = await _service.StructuredAnswerAsync(request, ct);
            return Ok(res);
        }
    }
}
